<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
session.setAttribute("middle", "个人管理");
session.setAttribute("end", "修改密码");
	if(session.getAttribute("password2")==null){
		response.sendRedirect( "login2.jsp?pageUrl=user/cp.jsp");
		return;
	}
String authType = request.getParameter("authType");
if(authType == null || authType.length() == 0){
	authType = String.valueOf(1);
}
request.setAttribute("authType", authType);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><fmt:message key="i18n.update"/><fmt:message key="i18n.loginPassword"/>-<fmt:message key="i18n.title"/> </title>
<script type="text/javascript" src="${basePath}scripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="${basePath}scripts/script.js"></script>
<jsp:include page="common.jsp"></jsp:include>
</head>
<body>
<jsp:include page="page_head.jsp"></jsp:include>
	<div class="row">
		<div class="col-md-12">
		<div class="box border primary">
			<div class="box-title">
				<h4><i class="fa fa-bars"></i><fmt:message key="i18n.update"/><fmt:message key="i18n.password"/></h4>
			</div>
			<div class="box-body big">
				<div class="col-md-12" style="text-align: center;">
		      		&nbsp;&nbsp;&nbsp;&nbsp;
		      		<c:if test="${authType ne '1' }"><a href="cp_new.jsp?authType=1"><input type="radio"/>通过原密码修改</a></c:if>
		      		<c:if test="${authType eq '1' }"><input type="radio" /><b style="color: red;margin-right: 30px;">通过原密码修改</b></c:if>
		      		<c:if test="${authType eq '2' }"><input type="radio"  style="margin-left: 30px;"/><b style="color: red;margin-right: 30px;">通过手机号码修改</b></c:if>
		      		<c:if test="${authType ne '2' }"><a href="cp_new.jsp?authType=2"><input type="radio" />通过手机号码修改</a>
		      		</c:if>
				</div>
				<h3 class="form-title"><fmt:message key="i18n.loginPassword"/></h3>
				<form class="form-horizontal" role="form" id="cp1_form" action="registerUser!changePassword.action" method="post" >
				<input type="hidden" id="cp1_loginName" name="registerUserDTO.loginName" value="${session.loginName }" />
      	<input type="hidden"  name="pageUrl" value="cp.jsp?authType=${authType }" />
      	<input type="hidden"  name="registerUserDTO.authType" value="${authType }" />
      		<c:if test="${authType eq '1' }"><!-- 原密码 -->
				<h5 style="text-align: center;color: red;">（如果不需要修改，请留空）</h5>
				  <div class="form-group">
					<label class="col-sm-3 control-label">当前密码：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="当前密码" name="registerUserDTO.oldPassword1" id="cp1_oldPassword1">
					</div>
				  </div>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.newPassword"/>：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="<fmt:message key="i18n.newPassword"/>" name="registerUserDTO.password1" id="cp1_newPassword">
					</div>
				  </div>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.cofimPassword"/>：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="<fmt:message key="i18n.cofimPassword"/>" id="cp1_cofimPassword">
					</div>
				  </div>
				  
				  
				  <h3 class="form-title"><fmt:message key="i18n.tradePassword" /></h3>
				<h5 style="text-align: center;color: red;">（如果不需要修改，请留空）</h5>
				  <div class="form-group">
					<label class="col-sm-3 control-label">当前密码：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="当前密码" name="registerUserDTO.oldPassword2" id="cp2_oldPassword2">
					</div>
				  </div>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.newPassword"/>：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="<fmt:message key="i18n.newPassword"/>"  name="registerUserDTO.password2" id="cp2_newPassword" >
					</div>
				  </div>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.cofimPassword"/>：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="<fmt:message key="i18n.cofimPassword"/>"  id="cp2_cofimPassword" >
					</div>
				  </div>
				  <c:if test="${not empty session.activationTime}">
					  <div class="form-group">
						<label class="col-sm-3 control-label"></label>
						<div class="col-sm-9">
							<button onclick="changePassword1()" class="btn btn-primary" style="width:15em;"><fmt:message key="i18n.update"/></button>
						</div>
					  </div>
				  </c:if>
				  <c:if test="${empty session.activationTime}">
					  <div class="form-group">
						<label class="col-sm-3 control-label"></label>
						<div class="col-sm-9">
							<button class="btn btn-primary" style="width:15em;">未激活（如需激活请联系注册时填写的运营中心）</button>
						</div>
					  </div>
				  </c:if>
				  
      	</c:if>
      	<c:if test="${authType eq '2' }"><!-- 手机验证码 -->
				<h5 style="text-align: center;color: red;">（如果不需要修改，请留空）</h5>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.newPassword"/>：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="<fmt:message key="i18n.newPassword"/>" name="registerUserDTO.password1" id="cp1_newPassword">
					</div>
				  </div>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.cofimPassword"/>：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="<fmt:message key="i18n.cofimPassword"/>" id="cp1_cofimPassword">
					</div>
				  </div>
				  
				  
				  <h3 class="form-title"><fmt:message key="i18n.tradePassword" /></h3>
				<h5 style="text-align: center;color: red;">（如果不需要修改，请留空）</h5>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.newPassword"/>：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="<fmt:message key="i18n.newPassword"/>" name="registerUserDTO.password2" id="cp2_newPassword" >
					</div>
				  </div>
				  <div class="form-group">
					<label class="col-sm-3 control-label"><fmt:message key="i18n.cofimPassword"/>：</label>
					<div class="col-sm-9">
					  <input type="password" class="form-control" placeholder="<fmt:message key="i18n.cofimPassword"/>"  id="cp2_cofimPassword" >
					</div>
				  </div>
				  <c:if test="${not empty session.activationTime}">
					  <div class="form-group">
						<label class="col-sm-3 control-label"></label>
						<div class="col-sm-9">
							<button onclick="changePassword2()" class="btn btn-primary" style="width:15em;"><fmt:message key="i18n.update"/></button>
						</div>
					  </div>
				  </c:if>
				  <c:if test="${empty session.activationTime}">
					  <div class="form-group">
						<label class="col-sm-3 control-label"></label>
						<div class="col-sm-9">
							<button class="btn btn-primary" style="width:15em;">未激活（如需激活请联系注册时填写的运营中心）</button>
						</div>
					  </div>
				  </c:if>
      	</c:if>
				  </div>
				 </form>
			</div>
		</div>
	</div>
	

<jsp:include page="page_foot.jsp"></jsp:include>
<script src="../scripts/user/common.js"></script>
<script type="text/javascript">
	var authType = "${authType}";
	$(function(){
		document.onkeydown = function(evt){
			var evt = window.event?window.event:evt;
			if(evt.keyCode==13){
				if(authType === '1'){
					changePassword1();
				}else{
					changePassword2();
				}
			}
		}
	});
	
	function changePassword1(){
		if(!hasText($('#cp1_oldPassword1').val())
				&& !hasText($('#cp2_oldPassword2').val())){
			/* alert('当前密码(登录密码)不能为空!');
			$('#cp1_oldPassword1').focus();return false; */
			alert('没有需要修改的密码');return;
		}
		if(hasText($('#cp1_oldPassword1').val())){
			if($('#cp1_newPassword').val()==''){
				alert('登录密码不能为空!');
				$('#cp1_newPassword').focus();
				return false;
			}
			if($('#cp1_newPassword').val()!=$('#cp1_cofimPassword').val()){
				alert('登录密码两次输入不正确!');
				$('#cp1_cofimPassword').focus();
				return false;
			}
		}
		/* if($('#cp1_newPassword').val()==''){
			alert('Login password can not be empty(登录密码不能为空)!');
			$('#cp1_newPassword').focus();
			return false;
		} */
		if(hasText($('#cp2_oldPassword2').val())){
			if($('#cp2_newPassword').val()==''){
				alert('交易密码不能为空!');
				$('#cp2_newPassword').focus();
				return false;
			}
			if($('#cp2_newPassword').val()!=$('#cp2_cofimPassword').val()){
				alert('交易密码两次输入不正确!');
				$('#cp2_cofimPassword').focus();
				return false;
			}
		}
		
		/* if($('#cp2_newPassword').val()==''){
			alert('Trading password can not be empty(交易密码不能为空)!');
			$('#cp2_newPassword').focus();
			return false;
		} */
		
		
		/* 
		if($('#cp_passwordAnswer').val()==''){
			alert('Secret security answer allowed is empty(密保答案不允许为空)!');
			$('#cp_passwordAnswer').focus();
			return false;
		} */
		/* if($('#cp_validCode').val()==''){
			alert('Verification code cannot be empty(验证码不能为空)!');
			$('#cp_validCode').focus();
			return false;
		} */
		/* $.post('activationCode!authEmailCode.action','dto.type=邮件&dto.category=UpdatePassword&dto.activationCode='+$('#cp_validCode').val(),function(res){
			 if(!res){
				 alert('E-mail verification code is not correct(邮箱验证码不正确)!');
				 return false;
			 }else{
				 $('#cp1_form').submit();
			 }
		}); */
		$('#cp1_form').submit();
	}
	function changePassword2(){
		if(!hasText($('#cp1_newPassword').val())
				&& !hasText($('#cp2_newPassword').val())){
			/* alert('当前密码(登录密码)不能为空!');
			$('#cp1_oldPassword1').focus();return false; */
			alert('没有需要修改的密码');return;
		}
		if(hasText($('#cp1_newPassword').val())){
			if($('#cp1_newPassword').val()==''){
				alert('登录密码不能为空!');
				$('#cp1_newPassword').focus();
				return false;
			}
			if($('#cp1_newPassword').val()!=$('#cp1_cofimPassword').val()){
				alert('登录密码两次输入不正确!');
				$('#cp1_cofimPassword').focus();
				return false;
			}
		}
		if(hasText($('#cp2_newPassword').val())){
			if($('#cp2_newPassword').val()==''){
				alert('交易密码不能为空!');
				$('#cp2_newPassword').focus();
				return false;
			}
			if($('#cp2_newPassword').val()!=$('#cp2_cofimPassword').val()){
				alert('交易密码两次输入不正确!');
				$('#cp2_cofimPassword').focus();
				return false;
			}
		}
		if($('#cp_validCode').val()==''){
			alert('验证码不能为空!');
			$('#cp_validCode').focus();
			return false;
		}
		$('#cp1_form').submit();
	}
</script>
</body>
</html>